#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:student_controller.py
# author:张世航
# datetime:2024/12/21 01:30
# software: PyCharm
"""
this is function  description 
"""
# controller/student_controller.py
from models.student import Student
from utils.db import Session

def add_student(sno, sname, ssex, sage, dno, sclass, address):
    session = Session()
    new_student = Student(Sno=sno, Sname=sname, Ssex=ssex, Sage=sage, Dno=dno, Sclass=sclass, address=address)
    session.add(new_student)
    session.commit()
    session.close()

def delete_student(sno):
    session = Session()
    student = session.query(Student).filter(Student.Sno == sno).first()
    if student:
        session.delete(student)
        session.commit()
    session.close()

def query_student_by_name(name):
    session = Session()
    students = session.query(Student).filter(Student.Sname == name).all()
    session.close()
    return students